<?php
/**
* Display the summary of transactions credits
*
* @author       Fabrice Douteaud <admin@clearbudget.net>
* @package      snippets
* @access       public
*/

/***********************************************************************

  Copyright (C) 2008  Fabrice Douteaud (admin@clearbudget.net)

    This file is part of ClearBudget.

    ClearBudget is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    ClearBudget is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with ClearBudget.  If not, see <http://www.gnu.org/licenses/>.


************************************************************************/
//prevent direct access
if(!defined('ENGINEON')) die('Direct access forbidden');

?>
<div class="tableDiv">
<table class="tableReport">
<caption><?php echo $keys->tableTitle_credit; ?></caption>
<tr><th><?php echo $keys->text_Credit; ?></th>
<?php
foreach($dates as $date) {
  echo '<th class="nobg">'.$date.'</th>';
  }
?>
 <th><?php echo $keys->text_Total; ?></th>
 <th><?php echo $keys->text_Percent; ?></th>
 <th><?php echo $keys->text_Average; ?></th>
</tr>
<?php
foreach($categories as $id=>$name) {
  // build the category link
  $link = '<a href="#" action="listCategoryItems_categorySelected='.$id.'_debit=0_backAction=tableCredits">'.$report->getCategoryName($id).'</a>';
  // get the total for that category
  (isset($totalCredits[$id]))? $total = $report->formatNumber($totalCredits[$id]): $total = 'n/a';
  // if total=0 we skip this category
  if($total == 0) continue;
  // start the row
  echo '<tr><td class="category">'.$link.'</td>';
  // loop over the column
  $count = 0;
  foreach($dates as $date) {
    // get the total for that category and date
    (isset($credits[$id][$date]))? $amount=$report->formatNumber($credits[$id][$date]):$amount='n/a';
    // print the column
    echo '<td>'.$amount.'</td>';
    $count ++;
    }
  // print the total and average
  echo '<td class="total">'.$total.'</td>';
  echo '<td>'.$creditsPctPerCategory[$id].'</td>';
  echo '<td>'.sprintf("%.2f",($total/$count)).'</td></tr>';
  }
 ?>
<tr><th><?php echo $keys->text_Total; ?></th>
<?php
foreach($dates as $date) {
  if(isset($totalCreditsPerMonth[$date])) echo '<th>'.$totalCreditsPerMonth[$date].'</th>';
  else echo '<th>'.$report->formatNumber(0).'</th>';
  }
?>
 <th><?php echo $report->totalCredits; ?></th>
 <th colspan="2"></th>
</tr>
</table>
</div>